<template>
<div class='page'>
  <div class='nav'>
    <div class="input_view flex_ac" @click="$back() ">
      <van-icon class="ml6" name="arrow-left" size="26" color="#000"/>
      <div class="nav_title">供需列表</div>
      <img class="mla mr10" width="22px" height="22px" src="~@/assets/img/xiangxian/search.png" alt="">
    </div>
    <div class="h15"></div>
    <Shaixuan :isCity="true" :isChain="true" @changeInit="changeInit" />
    <div class="h15"></div>
	</div>
  <div class="h100"></div>
  <div class="total">为您找到 <span style="color: #FA8A26;">{{ total }}</span> 条</div>
  <div class="box_div"  ref="gun">
    <van-list
      v-model="isLoad"
      :finished="isfinish"
      finished-text="没有更多了"
      @load="getMore"
      class="ml5 mr5"
      >
      <waterfall 
        :col="2"
        :data="list"
        :lazy-distance="1000"
        :gutterWidth="0"
      >
        <template>
          <div class="item_div" v-for="(item, index) in list" :key="index" @click="toDetail(item.id)">
            <div class="item_img_div">
              <img class="item_img" v-if="!item.isErr&&item.imgs" @error="item.isErr=true;$forceUpdate()" :src="item.imgs.split(',')[0]" alt="加载错误" />
              <img class="item_img" v-else src="http://guizhou-oss.oss-cn-guiyang-gzdata-d01-a.res.gzdata.com.cn/qiji/bgbgbg.png" />
            </div>
            <div class="item_title">{{ item.title }}</div>
            <div class="item_desc text_line">
              {{ item.desc }}
            </div>
          </div>
        </template>
      </waterfall>
    </van-list>
  </div>
</div>
</template>
<script>
import Shaixuan from '@/components/Shaixuan.vue'
import { xuqiu } from '@/api/api.js'
export default {
  components: {
    Shaixuan
  },
  data() {
    return {
      total: 0,
      page: 1,
      isfinish: false,
      isLoad: true,
      list:[]
    }
  },
  created() {
    this.init()
  },
  methods: {
    changeInit(query) {
      this.query = query
      this.init()
    },
    init() {
      this.page = 1
      this.isfinish = false
      this.isLoad = true
      this.list = []
      this.getList()
    },
    getMore() {
      if (this.isfinish||this.list.length==0) {
        return
      }
      this.page++
      this.getList()
    },
    getList() {
      let data = {
        page: this.page,
        ...this.query
      }
      xuqiu.getList({...data}).then(res => {
        this.isLoad = false
        this.list.push(...res.data.data)
        this.total = res.data.total
        if (this.list.length >= this.total) {
          this.isfinish = true
        }
      })
    },
    toDetail(id) {
      this.$router.push({name: 'gongxuDetail', query: {id}})
    }
  }
}
</script>
<style lang="scss" scoped>
.nav{
	width: 100%;
	position: fixed;
	top: 0;
	left: 0;
	background-color: rgba($color: #fff, $alpha: 1);
	z-index: 10;
	transition: all 0.5s;
}
.input_view{
	width: 100%;
  height: 40px;
	.nav_title{
		font-weight: 500;
		font-size: 18px;
		color: #000;
	}
}

.page{
	height:100%;
	width:100%;
	background: #F4F4F4;;
  .total{
    margin-left: 10px;
    font-size: 10px;
    color: #333333;
  }
}
.box_div{
  // margin: 0 10px 10px;
  // padding: 10px;
  // background: #FFFFFF;
  // box-shadow: 0px 3px 9px 2px rgba(250,135,30,0.13);
  // border-radius: 4px 4px 4px 4px;
  height: calc(100% - 115px);
  overflow: auto;
  .item_div{
    background: #FFFFFF;
    box-shadow: 0px 3px 9px 2px rgba(68,142,238,0.13);
    border-radius: 4px;
    margin-bottom: 10px;
    overflow: hidden;
    position: relative;
    margin: 10px 5px;
    .item_img_div{
      width: 100%;
      position: relative;
      .item_img{
        width: 100%;
        display: block;
        height: auto !important;
      }
    }
    .item_title{
      font-size: 14px;
      color: #333333;
      width: calc(100% - 20px);
      margin: 10px 10px 5px 10px;
    }
    .item_desc{
      width: calc(100% - 20px);
      font-size: 10px;
      color: #999999;
      margin: 0px 10px 10px 10px;
    }
  }
}
</style>